package com.qf.service.impl;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author WzYu
 * @date 2022-6-11 上午 10:46
 */
@Service("router")
@Slf4j
public class RouterFilterServiceImpl implements FilterChainService {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private AmqpAdmin amqpAdmin;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {

        log.info("[策略模块 - 路由策略] 策略开始执行");
        String name = RabbitMQConstants.TOPIC_SMS_GATEWAY + 1;
        //创建队列
        amqpAdmin.declareQueue(QueueBuilder.durable(name).build());
        //发送消息
        rabbitTemplate.convertAndSend(name,standardSubmit);
        //记录日志
        log.info("[策略模块 - 路由策略] 路由策略执行成功！！！消息发送到了网关模块对应的队列");
        return true;
    }
}
